package com.example.demo.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;

@RestController
public class Pdf {

    @Value("${shellName}")
    String shellName;

    @GetMapping (value = "exec")
    public void execShell(HttpServletRequest request) throws UnsupportedEncodingException {
//        192.168.137.100:8080/testShell/shell.jsp?shell=echo hello
//        String URL = request.getParameter("shell");
//        String shell = URLDecoder.decode( URL, "UTF-8" );
//        System.out.println(shell);
        // Runtime.getRuntime().exec(shell);
        /*
        ababa
        ababa
        ababa
        ababa
        ababa
        ababa
        ababa
        ababa
         */
        System.out.println("babashellNameshellName");
        System.out.println("babashellNameshellName");
        System.out.println("babashellNameshellName");
        System.out.println("babashellNameshellName");
        System.out.println("babashellNameshellName");
        System.out.println("babashellNameshellName");
        System.out.println("babashellNameshellName");
        System.out.println("babashellNameshellName");
        try {
            String shellPath = "/usr/local/gitee/demo/confidential-documents";
            shellPath += File.separator + shellName;
            Process process = Runtime.getRuntime().exec(shellPath);
            int exitValue = process.waitFor();
            if (0 != exitValue) {
                System.out.println("寄");
            }
            System.out.println("运行成功");
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }

}
